from . import dbx
from .sql_exec import SqlExec, Page

def createSqlIdExec(sql_id: str) :
    assert sql_id, "Parameter 'sql_id' must not be none"
    return SqlIdExec(sql_id, dbx)


def createPage(page_num: int, page_size: int) :
    return SqlIdPage(None, page_num, page_size)


class SqlIdExec(SqlExec):

    def save(self, *args, **kwargs):
        return self.executor.save(self.sql, *args, **kwargs)

    def page(self, page_num=1, page_size=10):
        return SqlIdPage(self, page_num, page_size)


class SqlIdPage(Page):

    def sql(self, sql: str):
        self._sql_exec = createSqlIdExec(sql)
        return self
